package hyl.base.flow.express;

import java.util.HashMap;
import java.util.Map;

/**
 * 存放结果配置的每个状态键值对
 */
public class ResultItem {
	/** 结果表达式 */
	String itemexp;

	/** 结果集合 */
	Map<String, Character> itemmap = new HashMap<>();

	public ResultItem(String express, Character defchar) {
		itemexp = express;

		// 解析表达式
		int f = 0;
		StringBuilder field = new StringBuilder();
		for (int i = 0; i < itemexp.length(); i++) {
			char c = itemexp.charAt(i);
			if (c == '=') {
				f = 1;
			} else if (c == ',') {
				if (f < 2) {
					itemmap.put(field.toString(), defchar);
				}
				f = 0;
				field.setLength(0);
			} else if (c == ' ') {
				continue;
			} else {
				if (f == 0) {
					field.append(c);
				} else if (f == 1) {
					if (field.length() == 0)
						continue;
					itemmap.put(field.toString(), c);
					f = 2;
				}
			}
		}
		if (f < 2) {
			itemmap.put(field.toString(), defchar);
		}

	}

	public 	Map<String, Character> getValues() {
	   return itemmap;
	}

}
